//
//  CustomTableViewCell.swift
//  BUYOU
//
//  Created by tyuu on 2024/6/1.
//

import UIKit

class CustomTableViewCell: UITableViewCell {
    
    
    // 日期标签
    let dateLabel: UILabel = {
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: 14)
        label.textColor = .gray
        return label
    }()
    
    // 海报图片视图
    let posterImageView: UIImageView = {
        let imageView = UIImageView()
        imageView.contentMode = .scaleAspectFit
        return imageView
    }()
    
    // 标题标签
    let titleLabel: UILabel = {
        let label = UILabel()
        label.font = UIFont.boldSystemFont(ofSize: 16)
        label.textColor = .blue
        label.numberOfLines = 0
        return label
    }()
    
    // 描述标签
    let descriptionLabel: UILabel = {
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: 14)
        label.textColor = .darkGray
        label.numberOfLines = 0
        return label
    }()
    
    // 分享按钮
    let shareButton: UIButton = {
        let button = UIButton()
        button.setTitle("一键分享", for: .normal)
        button.setTitleColor(.orange, for: .normal)
        button.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        return button
    }()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        selectionStyle = .none
        
        contentView.addSubview(dateLabel)
        contentView.addSubview(posterImageView)
        contentView.addSubview(titleLabel)
        contentView.addSubview(descriptionLabel)
//        contentView.addSubview(shareButton)
        
        setupConstraints()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // 设置布局
    private func setupConstraints() {
        dateLabel.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(8)
            make.left.equalToSuperview().offset(16)
        }
        
        posterImageView.contentMode = .scaleAspectFill
        posterImageView.layerCornerRadius = 10
        posterImageView.snp.makeConstraints { make in
            make.top.equalTo(dateLabel.snp.bottom).offset(8)
            make.left.equalToSuperview().offset(16)
            make.width.equalTo(100)
            make.height.equalTo(150)
            make.bottom.equalToSuperview().offset(-8)
        }
        
        titleLabel.snp.makeConstraints { make in
            make.top.equalTo(dateLabel.snp.bottom).offset(8)
            make.left.equalTo(posterImageView.snp.right).offset(16)
            make.right.equalToSuperview().offset(-16)
        }
        
        descriptionLabel.snp.makeConstraints { make in
            make.top.equalTo(titleLabel.snp.bottom).offset(8)
            make.left.equalTo(posterImageView.snp.right).offset(16)
            make.right.equalToSuperview().offset(-16)
        }
        
        
    }
    
    // 配置Cell
    func configure(with activity: RunActivity) {
        dateLabel.text = activity.dateTime
        posterImageView.image = UIImage(named: activity.coverImageUrl)
        titleLabel.text = activity.name
        descriptionLabel.text = activity.description
    }
    
}
